﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Drawing;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OrganizedIN.DAL;
using OrganizedIN.BAL;
using OrganizedIN.BussinessServices;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using OrganizedIN.BAL.Common;

namespace OrganizedIN.UI.ToDo
{
    public partial class MyToDos : System.Web.UI.Page
    {
        string strUserName;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            strUserName = Convert.ToString(Session["UserID"]);
            try
            {
                if (!IsPostBack)
                {
                    DateTime dt = DateTime.Now;
                    lblTodayDate.Text = String.Format("{0:D}", dt);                    
                    BindList();                    
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public void BindList()
        {
            try
            {
                DataSet ds = new DataSet();
                ds = Common.Get_Todo_List(strUserName,"");
                gvTodoList.DataSource = ds.Tables[0];
                gvTodoList.DataBind();

                if (ds.Tables[0].Rows.Count > 0)
                {
                    lblErrMsg.Text = "";
                }
                else
                {
                    lblErrMsg.Text = "No record(s) found.";
                }
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.ToString();
            }
        }

        
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = Common.Get_Todo_List(strUserName, txtsrchbydate.Text);
                gvTodoList.DataSource = ds.Tables[0];
                gvTodoList.DataBind();

                if (ds.Tables[0].Rows.Count > 0)
                {
                    lblErrMsg.Text = "";
                }
                else
                {
                    lblErrMsg.Text = "No record(s) found.";
                }
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.ToString();
            }
        }
        
        protected void gvTodoList_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            gvTodoList.PageIndex = e.NewSelectedIndex;
            gvTodoList.DataBind();
        }

        //- Start : ReName
        protected void lbtnDemo_Click(object sender, EventArgs e)
        {
            LinkButton lbtnEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lbtnEdit.NamingContainer;

            lblID_ReName.Text = row.Cells[0].Text;
            txtRename.Text = row.Cells[1].Text;
            UpdatePanel1.Update();
            this.mpePerson.Show();
        }

        protected void btnSavePerson_Click(object sender, EventArgs e)
        {
            Common.Todo_AjaxUpdates(lblID_ReName.Text, "ReName", txtRename.Text);
            this.mpePerson.Hide();
            BindList();
        }
        //- End : ReName

        //- Start : Summary
        protected void lbtnSummary_Click(object sender, EventArgs e)
        {
            LinkButton lbtnEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lbtnEdit.NamingContainer;

            lblSummary.Text = row.Cells[1].Text;
            lblDesc.Text = row.Cells[2].Text;
            UpdatePanel1.Update();
            this.mpSummary.Show();
        }
        //- End : Summary

        //- Start : ReDate
        protected void lbtnReDate_Click(object sender, EventArgs e)
        {
            LinkButton lbtnEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lbtnEdit.NamingContainer;

            lblID_ReDate.Text = row.Cells[0].Text;            
            UpdatePanel1.Update();
            this.mpReDate.Show();
        }
        
        protected void btnSave_ReDate_Click(object sender, EventArgs e)
        {
            Common.Todo_AjaxUpdates(lblID_ReDate.Text, "ReDate", txtReDate.Text);
            this.mpReDate.Hide();
            BindList();
            
        }
        //- End : ReDate

        //- Start : Archive
        protected void lbtnArchive_Click(object sender, EventArgs e)
        {
            LinkButton lbtnEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lbtnEdit.NamingContainer;

            lblID_Archive.Text = row.Cells[0].Text;
            UpdatePanel1.Update();
            this.mpArchive.Show();
        }

        protected void btnSave_Archive_Click(object sender, EventArgs e)
        {
            Common.Todo_AjaxUpdates(lblID_Archive.Text, "Archive", "");
            this.mpArchive.Hide();
            BindList();
        }
        //- End : Archive

        //- Start : Mark
        protected void lbtnMark_Click(object sender, EventArgs e)
        {
            LinkButton lbtnEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lbtnEdit.NamingContainer;

            lblID_Mark.Text = row.Cells[0].Text;
            UpdatePanel1.Update();
            this.mpMark.Show();
        }

        protected void btnSave_Mark_Click(object sender, EventArgs e)
        {
            Common.Todo_AjaxUpdates(lblID_Mark.Text, "Mark", "");
            this.mpArchive.Hide();
            BindList();
        }
        //- End : Mark

        //- Start : Delete
        protected void lbtnDelete_Click(object sender, EventArgs e)
        {
            LinkButton lbtnEdit = sender as LinkButton;
            GridViewRow row = (GridViewRow)lbtnEdit.NamingContainer;

            lblID_Delete.Text = row.Cells[0].Text;
            UpdatePanel1.Update();
            this.mpDelete.Show();
        }

        protected void btnSave_Delete_Click(object sender, EventArgs e)
        {
            Common.Todo_AjaxUpdates(lblID_Delete.Text, "Delete", "");
            this.mpDelete.Hide();
            BindList();
        }
        //- End : Delete
        
    }
}
